package com.xiaomai.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaomai.commonutil.R;
import com.xiaomai.eduservice.entity.EduCourse;
import com.xiaomai.eduservice.entity.EduTeacher;
import com.xiaomai.eduservice.service.EduCourseService;
import com.xiaomai.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherFront")

public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable Long page, @PathVariable Long limit){
    //创造分页条件对象,baseMapper需要传入该对象
        Page<EduTeacher> pageTeacher = new Page<EduTeacher>(page,limit);
        //将分页条件对象作为参数，调用查询数据库，使用map集合封装
        Map<String,Object> map  = teacherService.getTeacherFrontList(pageTeacher);
        return R.ok().data(map);
    }

    //查询讲师详情信息 包括讲师信息与课程信息
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public  R getFrontInfo(@PathVariable String teacherId){
        //查询教师信息
        EduTeacher teacher = teacherService.getById(teacherId);
        //查询课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
